package com.game.number;

import java.util.Comparator;

public class UnitComparator implements Comparator<Unit>{

	@Override
	public int compare(Unit unitA, Unit unitB) {
		String[] unitAPos=unitA.getSplitPosition();
		String[] unitBPos=unitB.getSplitPosition();
		
		if(unitAPos.length!=unitBPos.length)
			throw new RuntimeException("Two compare Unit must have same dimension");
		
		for(int i=unitAPos.length-1;i>=0;i--){
			if(Integer.parseInt(unitAPos[i])<Integer.parseInt(unitBPos[i]))
				return -1;
			if(Integer.parseInt(unitAPos[i])>Integer.parseInt(unitBPos[i]))
				return 1;
		}
		return 0;
	}
	
	public static void main(String[] args){
		Unit unitA=new Unit("2,2","4");
		Unit unitB=new Unit("2,3,3","4");
		UnitComparator com=new UnitComparator();
		System.out.println(com.compare(unitA, unitB));
	}
	
}
